package com.dr.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dr.pojo.User;
import com.dr.service.LoginService;




@RestController
@RequestMapping("/ajax")
public class LoginController_ajax {
	@Autowired
	private LoginService service;
	
	@RequestMapping("/login")
	public Map<String,Object> login(User user, HttpSession session) {
		Map<String,Object> result = new HashMap<>();
		User loginUser = service.findUser(user);
		if(loginUser==null) {
			//登录失败
			result.put("status", "0");//登录失败，返回失败标记
		}
		else {
			session.setAttribute("loginUser",loginUser);//登录用户记录Session
			result.put("status", "1");//登录成功，返回成功标记
		}
		return result;
	}

}
